package com.situ.blog.service.impl;

import com.situ.blog.dao.IBlogDao;
import com.situ.blog.dao.impl.BlogDaoImpl;
import com.situ.blog.listener.BlogExcelListener;
import com.situ.blog.pojo.Blog;
import com.situ.blog.pojo.query.BlogQuery;
import com.situ.blog.pojo.vo.BlogVO;
import com.situ.blog.service.IBlogService;
import com.situ.blog.util.ExcelUtil;
import com.situ.blog.util.PageResult;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

public class BlogServiceImpl implements IBlogService {
    private IBlogDao blogDao = new BlogDaoImpl();

    @Override
    public PageResult<BlogVO> selectByPage(BlogQuery blogQuery) {
        List<BlogVO> list = blogDao.selectByPage(blogQuery);
        int count = blogDao.selectTotalCount(blogQuery);
        return new PageResult<>(0, "", count, list);
    }

    @Override
    public void add(Blog blog) {
        blogDao.add(blog);
    }

    @Override
    public Blog selectById(int id) {
        return blogDao.selectById(id);
    }

    @Override
    public void update(Blog blog) {
        blogDao.update(blog);
    }

    @Override
    public void exportExcel(HttpServletResponse resp) {
        List<Blog> list = blogDao.selectAll();
        ExcelUtil.exportExcel(resp, list, Blog.class, "blog");
    }

    @Override
    public void importExcel(HttpServletRequest req) {
        ExcelUtil.importExcel(req, new BlogExcelListener(), Blog.class);
    }
}
